#!/usr/bin python
# -*- coding: utf-8 -*-
"""任务信息api接口"""
import json
from flask import jsonify, request, make_response
from flask import Blueprint

from gtm_server.services.task import get_all_task_major_info
from gtm_server.services.task import create_task


task_bp = Blueprint("task", __name__, url_prefix="/task")


@task_bp.route("/alltaskquery", methods=["GET"])
def api_all_task_query():
    # tasks is a list
    tasks_info = {}
    tasks = get_all_task_major_info()
    tasks_info["tasks_info"] = tasks
    response = json.dumps(tasks_info)

    return response


@task_bp.route("/onetaskquery", methods=["POST"])
def api_one_task_query():
    """
    # TODO:获取单个任务
    """
    return


@task_bp.route("/createtask", methods=["PUT"])
def api_create_task():
    """
    创建路线规划的任务
    """
    request_data = request.json
    print(f"controller:{request_data}")
    result = create_task(data=request_data)
    response = make_response(jsonify(result))
    return response
